Skip to content

fix(eew): keep cancelled, stale and out-of-order alerts honest - #616

Merged
whes1015 merged 6 commits into
mainfrom
fix/eew-cancel-and-ordering
Oct 16, 2026
Merged

whes1015 merged 6 commits into
mainfrom
fix/eew-cancel-and-ordering

Conversation

@whes1015

@whes1015 whes1015 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Stack 第 1/6 層:#616 → #615 → #618 → #619 → #620 → #621,請由下往上合併(#614 已合併)。這是最底層,base 是 main。

這個 PR 做了什麼

讓地震速報(EEW)在幾種邊界情況下不再誤導使用者:被取消的速報照樣以警報顯示、伺服器落後時卡片的報數倒退、連線斷掉後舊速報一直留在畫面上、多則速報同時發布時挑錯主要的那則,以及速報連線中斷時首頁看起來像「沒有警報」。

status 的意義(查證結果)

API 的 status 是各發布單位原樣轉傳的狀態碼,取消的代碼依單位而不同:

值 意義 依據
0 預警 各端一致
1 警報 TREM-Lite eew.ts L81、L159
3 取消(CWA) TREM-Lite eew.ts L159、L225;trem-monitor use-trem-data.ts
2 取消(nied) eew-server-go internal/models/eew.go:24、fetcher/nied.go:134-137;Nginx nats.lua 原樣轉傳

final 是另一回事,只表示該單位的最後一報,和取消無關。app 把 2 和 3 都當作取消,不認得的值一律當一般速報,讀錯也絕不會藏掉一則警報。對照表寫在 eew.dart 的註解裡。

改動內容

正式程式碼

  • 2908b670 取消的速報顯示為「已取消」
    • 卡片、橫幅和重播頁顯示中性的「已取消」標籤與說明。
    • 取消的事件沒有倒數、沒有本地震度推估、沒有波前圈、沒有地區著色、不播報;正在播報的語音會被打斷。
  • fd1bad3c 伺服器落後時保留最新一報
    • 新增純函式 reducer(eew_feed.dart):每個「單位+事件」只保留最大的報數,卡片不會從第 3 報退回第 2 報,也不會遺失取消狀態;伺服器移除的事件仍會立刻消失。
    • 套用在 EewRealtimeSource.fetch,串流和 fix(eew): detect and recover from silently dropped live feeds #614 的輪詢回退兩條路都會經過。
  • fea74991 停止更新的速報會自動移除
    • 以校正時間(AppTime)計算,常數都寫明物理依據:一般在發震後 250 秒;深度 ≥150 km、規模 ≥6 或警報延長到 400 秒;取消後 180 秒;硬上限 1 小時。
    • 以 CWA 走時表估算,淺層地震 S 波到 600 km 外約 145 秒。
  • 19711161 多則速報時先顯示、先播報最重要的那則
    • 純函式排序(eew_priority.dart):還沒到達的優先,再來是本地震度最大,再來是最新一報;取消的排最後。
    • 套用在首頁卡片、首頁橫幅和語音播報。模型多了可為 null 的 reportTime(JSON 的 time)。
  • 2f43c329 速報連線中斷時明確告知
    • 速報連線 stale 或 offline 時,首頁橫幅位置、首頁速報區塊和強震監視器狀態列都顯示「地震速報連線中斷,重新連線中…」。
    • 原本這些地方什麼都不畫,空白會被讀成「沒有警報」。新增共用元件,12 個 ARB 都有翻譯。
  • 2b3bcd66 S 波倒數準確到抵達的那一刻
    • 推估保留毫秒,顯示的秒數無條件進位。
    • tick 對齊校正時間:平常對齊整秒,倒數時對齊「距離抵達的整秒」,所以「已抵達」剛好在算出的那一刻切換,畫面上的秒數也不會過時。

測試

  • 單元測試:狀態對照、reducer、過期規則、排序、倒數計算、tick 對齊。
  • widget 測試:取消的卡片、橫幅、狀態列;連線中斷提示;抵達瞬間的切換。
  • source 層級:重連到落後的伺服器、開著但沉默的連線。

相關 issue

沒有對應的 issue,是檢查速報顯示流程時發現的。

怎麼驗

  • tool/commit.sh --push 通過(analyze、codegen、全部 Dart 測試)。
  • 需要確認:
    • CWA 的取消是否真的是 3 尚未用真實資料確認:本機資料庫只有 CWA 的 0 和 1。請用一筆真實的 CWA 取消速報驗證。
    • 連線中斷提示會在 app 背景超過約 10 秒後回到前景時閃一下:SSE 重連前速報連線確實是斷的,所以提示是正確的,但請在實機上看是否可接受。
    • 取消與中斷樣式在淺色/深色模式下的樣子,以及泰文、菲律賓文等較長語系下橫幅是否一行放得下。
  • 刻意保留的小差異:
    • 首頁橫幅以鄉鎮中心排序,卡片用 GPS 位置,兩者不會同時出現在畫面上。
    • 強震監視器點擊切換卡片時維持來源順序,不照排序。
    • 示範與重播來源不經過 reducer。

檢查清單

  • tool/check/commits.sh 通過
  • 一個 commit 一件事
  • analyze 與測試通過(tool/commit.sh --push)
  • 新的使用者可見字串都走 AppLocalizations,12 個語系都有翻譯
  • UI 變更使用設計 token;深色模式與長語系待實機確認

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.29730% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.46%. Comparing base (807f5d9) to head (2b3bcd6).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
...es/map/presentation/widgets/rts_monitor_panel.dart 91.89% 3 Missing ⚠️
...features/earthquake/domain/eew_local_estimate.dart 91.66% 2 Missing ⚠️
...thquake/presentation/pages/report_replay_page.dart 88.23% 2 Missing ⚠️
...home/presentation/widgets/home_monitor_banner.dart 95.83% 2 Missing ⚠️
.../features/earthquake/data/eew_realtime_source.dart 83.33% 1 Missing ⚠️
...ib/features/map/presentation/layers/rts_layer.dart 87.50% 1 Missing ⚠️

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@whes1015

whes1015 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member Author

Force-push:rebase 到目前的 main(807f5d9d),並把開著的 PR 排成 stack:#614 → #616 → #615 → #618 → #619 → #620 → #621,base 改成下面那一層的分支。

和 main 及其他 PR 的衝突都是兩邊各自新增的內容,雙方都保留;ARB 在檔尾補逗號後重新產生 l10n。每一層都單獨跑過 analyze 和完整測試,頂端跑過 tool/commit.sh --push。

這一層的 commit 除了 ARB 檔尾那一行補上逗號以外,內容沒有變。

@whes1015
whes1015 added this pull request to stack #626 October 16, 2026 19:21
Base automatically changed from fix/realtime-feed-liveness to main October 16, 2026 19:21
Platform: all

Fix(zh-Hant): 地震速報被發布單位取消後會標示「已取消」,不再倒數、預估所在地震度、畫震波圈或語音播報
Fix(en-US): a cancelled earthquake alert is marked as cancelled instead of still counting down, estimating local shaking, drawing wave rings and being read aloud
Platform: all

Fix(zh-Hant): 切換連線伺服器時,地震速報不會再從較新的報數退回較舊的報數
Fix(en-US): an earthquake alert no longer steps back to an older report after the app switches servers
Platform: all

Fix(zh-Hant): 速報伺服器停止更新時,地震速報不會再一直停留在畫面上;已取消的速報顯示三分鐘後移除
Fix(en-US): an earthquake alert no longer stays on screen indefinitely when the server stops updating it, and a cancelled one clears after three minutes
Platform: all

Fix(zh-Hant): 同時有多筆地震速報時,首頁與語音播報會優先顯示震波尚未抵達、所在地預估震度最高的那一筆,已取消的排在最後
Fix(en-US): with several earthquake alerts at once, Home and the spoken announcement now lead with the one whose S-wave has not reached you yet and that shakes your location hardest, with cancelled ones last
Platform: all

Fix(zh-Hant): 地震速報連線中斷時,首頁與強震監視器會顯示「地震速報連線中斷,重新連線中」,不再以空白呈現而被誤認為平安無事
Fix(en-US): Home and the seismic monitor now say when the earthquake alert connection is lost, instead of showing an empty space that reads as all-clear
Platform: all

Fix(zh-Hant): 震波倒數改以毫秒精度計算並對齊時鐘整秒更新,「已抵達」會在預估抵達的瞬間切換,不再提早或延遲最多一秒
Fix(en-US): the S-wave countdown is now computed to the millisecond and ticks on the clock's whole seconds, so "Arrived" switches at the estimated moment instead of up to a second early or late
@whes1015
whes1015 force-pushed the fix/eew-cancel-and-ordering branch from e04d8da to 2b3bcd6 Compare October 16, 2026 19:31
@whes1015

Copy link
Copy Markdown
Member Author

Force-push:#614 合併後 rebase 到新的 main(238297ea),拿掉 #614 合併前的舊 commit。

內容沒有變:main 上合併進來的 tree 和 stack 第一層完全相同,搬過去之後每一層的 tree 也都和之前一樣,所以先前各層的 analyze 和測試結果仍然有效。

@whes1015
whes1015 merged commit 34336fb into main Oct 16, 2026
6 checks passed
@whes1015
whes1015 deleted the fix/eew-cancel-and-ordering branch October 16, 2026 19:33
@lowrt lowrt added this to the v26.4 milestone Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants